package com.lxhotel.agentmcp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lxhotel.agentmcp.domain.response.HotelRoomTypeInventoryResponse;
import com.lxhotel.agentmcp.entity.Hotel;
import com.lxhotel.agentmcp.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HotelMapper extends BaseMapper<User> {
    @Select("SELECT * FROM hotel limit 10")
    List<Hotel> selectAll();

    @Select("SELECT * FROM hotel where hotelName like CONCAT('%',#{name},'%')")
    List<Hotel> selectByHotelNameLike(String hotelName);

    @Select("SELECT  \n" +
            "  *,(  \n" +
            "    6371 * acos (  \n" +
            "      cos ( radians( #{amapLatitude} ) )  \n" +
            "      * cos( radians( amapLatitude ) )  \n" +
            "      * cos( radians( amapLongitude ) - radians( #{amapLongitude} ) )  \n" +
            "      + sin ( radians( #{amapLatitude} ) )  \n" +
            "      * sin( radians( amapLongitude ) )  \n" +
            "    )  \n" +
            "  ) AS distance  \n" +
            "FROM hotel\n" +
            "ORDER BY distance \n" +
            "LIMIT 1")
    Hotel getHotelByAmaqLongitudeAndLatitude(String amapLongitude, String amapLatitude);

    @Select("SELECT\n" +
            "hrti.id AS hotelRoomTypeInventoryId,\n" +
            "hrti.num,\n" +
            "hrti.bookingDate,\n" +
            "hrti.hotelRoomTypeId,\n" +
            "hrt.* \n" +
            "FROM\n" +
            "hotel_room_type_inventory hrti\n" +
            "JOIN hotel_room_type hrt ON hrti.hotelRoomTypeId = hrt.id\n" +
            "JOIN hotel h ON hrt.hotelId = h.id \n" +
            "WHERE\n" +
            "h.id = #{hotelId} \n" +
            "AND hrti.bookingDate = #{bookingDate}")
    List<HotelRoomTypeInventoryResponse> selectHotelRoomTypeInventoryByBookingDate(String bookingDate, Long hotelId);

    @Select("SELECT * FROM hotel where hotelName = #{name} limit 1")
    Hotel selectByHotelName(String name);
}
